<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 
        以get方式传递的数据 会将参数数据队列传递到action所指的地址栏中 用?分隔
    -->
    <form onsubmit="return false">
        <div>
            <label for="user">用户名:</label>
            <input name="user" type="text">
            <span class="user_span"></span>
        </div>
        <div>
            <label for="pwd">密&emsp;码:</label>
            <input name="pwd" type="text">
            <span class="pwd_span"></span>
        </div>
        <div>
            <button id="logBtn">注册</button>
            <input type="reset">
        </div>
    </form>
</body>
<script>
    var logBtn = document.getElementById("logBtn");
    var userInp = document.getElementsByName("user")[0];
    var pwdInp = document.getElementsByName("pwd")[0];


    logBtn.onclick = function () {
        var user = userInp.value;
        var pwd = pwdInp.value;

        // 以get方式传递的数据 需要将参数数据队列拼接到url之后 用?分隔

        var xhr = new XMLHttpRequest();

        // xhr.open("get", "../php/get.php?user=" + user + "&pwd=" + pwd, true);
        xhr.open("get", `../php/get.php?user=${user}&pwd=${pwd}`, true);

        xhr.send();

        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                var result = xhr.responseText;
                console.log(result);
                var data = JSON.parse(result);
                console.log(data);
            }
        }

    }



</script>

</html>